<template>
	<view class="cartcontrol">
		<view class="cart-decrease" v-show="food.count > 0" @click.stop="decrease($event)">
			<uv-icon name="minus-circle" size="24" color="#0b6ded" />
		</view>
		<view class="cart-count" v-show="food.count > 0">{{ food.count }}</view>
		<view class="cart-add" @click.stop="add($event)">
			<uv-icon name="plus-circle-fill" size="24" color="#0b6ded" />
		</view>
	</view>
</template>

<script>
	export default {
		props: {
			food: {
				type: Object
			}
		},
		methods: {
			add(event) {
				this.food.count++
				this.$emit('add', event.target)
			},
			decrease(event) {
				if (this.food.count > 0) {
					this.food.count--
				}
				this.$emit('decrease', event.target)
			},
		}
	}
</script>

<style lang="scss" scoped>
	.cartcontrol {
		display: flex;
		align-items: center;
	}

	.cart-decrease,
	.cart-add {
		cursor: pointer;
		transition: transform 0.2s;
	}

	.cart-decrease:active,
	.cart-add:active {
		transform: scale(0.9);
		/* 点击时按钮缩放 */
	}

	.cart-count {
		margin: 0 8px;
		font-size: 14px;
		color: #333;
		width: 18px;
		text-align: center;
	}
</style>